----------------------------------------------------------------------------------
-- Company: College of Engineering and Architecture
--
-- Engineers: Elias Medawar (medawar.elias@gmail.com), 
--			  Robin Franzi (robsoab@gmail.com)
--            Yves Peissard (ypeissard@gmail.com)
--            Simon Nissille (simon.nissille@edu.hefr.ch), 
-- 
-- Create Date:    15:49:27 26/05/2009 
-- Design Name: 
-- Module Name:    iTmer - Behavioral 
-- Project Name:   iTimer
-- Target Devices: Spartan2
-- Description:    This is the main file of the iTimer project.
--
--
-- Dependencies:   buttonHandler.vhd
--				   displayTime.vhd
--				   modeSwitcher.vhd
--				   TPU.vhd (Time Processing Unit)
--				   waitedTime.vhd
--				   wheelHandler.vhd
--                 
--
----------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity iTmer is
    Port ( 
           clockInput : in  STD_LOGIC:='0';
		   buttonInput : in STD_LOGIC := '0';
           wheelInputA : in  STD_LOGIC:='0';
           wheelInputB : in  STD_LOGIC:='0';
           alarm : out  STD_LOGIC:='0';
           segmentMinute0 : out  STD_LOGIC_VECTOR (3 downto 0):="0000";
           segmentMinute1 : out  STD_LOGIC_VECTOR (3 downto 0):="0000";
           segmentSeconde0 : out  STD_LOGIC_VECTOR (3 downto 0):="0000";
           segmentSeconde1 : out  STD_LOGIC_VECTOR (3 downto 0):="0000";
		   modeTemSwitcher: out STD_LOGIC_VECTOR (1 downto 0):="00"
			  );
end iTmer;

architecture Behavioral of iTmer is
-- wheelHandler Signals
	SIGNAL busDecrement,busIncrement,busMode :  STD_LOGIC_VECTOR (1 downto 0):="00";
	SIGNAL alarmInteren,simplePush,longPush : std_logic :='0';
	SIGNAL busTime : STD_LOGIC_VECTOR (12 downto 0):="0000000000000";
	
	COMPONENT buttonHandler
	PORT(
		buttonInput : IN std_logic;
		clockInput : IN std_logic;          
		simplePush : OUT std_logic;
		longPush : OUT std_logic
		);
	END COMPONENT;
	
	COMPONENT wheelHandler
	PORT(
		wheelInputA : IN std_logic;
		wheelInputB : IN std_logic;
		clockInput : IN std_logic;
		busMode : IN std_logic_vector(1 downto 0);          
		busDecrement : OUT std_logic_vector(1 downto 0);
		busIncrement : OUT std_logic_vector(1 downto 0)
		);
	END COMPONENT;
	
	COMPONENT modeSwitcher
	PORT(
		alarm : IN std_logic;
		simplePush : IN std_logic;
		longPush : IN std_logic;
		clockInput : IN std_logic;          
		busMode : OUT std_logic_vector(1 downto 0)
		);
	END COMPONENT;
	
	COMPONENT timeProcessingUnit
	PORT(
		clockInput : IN std_logic;
		busMode : IN std_logic_vector(1 downto 0);
		busDecrement : IN std_logic_vector(1 downto 0);
		busIncrement : IN std_logic_vector(1 downto 0);          
		busTime : OUT std_logic_vector(12 downto 0);
		alarmSignal : OUT std_logic
		);
	END COMPONENT;
	
	COMPONENT displayTime
	PORT(
		busTimer : IN std_logic_vector(12 downto 0);
		clockInput : IN std_logic;
		busMode : IN std_logic_vector(1 downto 0);          
		segment1 : OUT std_logic_vector(3 downto 0);
		segment2 : OUT std_logic_vector(3 downto 0);
		segment3 : OUT std_logic_vector(3 downto 0);
		segment4 : OUT std_logic_vector(3 downto 0)
		);
	END COMPONENT;
begin
	-- Der Component buttonHandler
	Inst_buttonHandler: buttonHandler PORT MAP(
		buttonInput =>buttonInput ,
		clockInput =>clockInput ,
		simplePush => simplePush,
		longPush => longPush
	);
	-- Der Component wheelHandler
	Inst_wheelHandler: wheelHandler PORT MAP(
		wheelInputA => wheelInputA,
		wheelInputB =>wheelInputB ,
		clockInput => clockInput,
		busMode => busMode,
		busDecrement =>busIncrement ,
		busIncrement =>busDecrement 
	);
	-- Der Component modeSwitcher
	Inst_modeSwitcher: modeSwitcher PORT MAP(
		busMode => busMode,
		alarm =>alarmInteren ,
		simplePush =>simplePush ,
		longPush =>longPush ,
		clockInput =>clockInput 
	);
			
	-- Der Component timeProcessingUnit
	Inst_timeProcessingUnit: timeProcessingUnit PORT MAP(
		clockInput => clockInput,
		busMode =>busMode ,
		busDecrement => busDecrement,
		busIncrement => busIncrement,
		busTime => busTime,
		alarmSignal =>alarmInteren 
	);
	
	-- Der Component displayTime		
	Inst_displayTime: displayTime PORT MAP(
		busTimer =>busTime ,
		clockInput =>clockInput ,
		busMode => busMode,
		segment1 => segmentMinute0,
		segment2 => segmentMinute1,
		segment3 => segmentSeconde0,
		segment4 => segmentSeconde1 
	);
			
	UpdateOutPut:PROCESS(clockInput)
	BEGIN
		IF rising_edge(clockInput) THEN
			alarm <= alarmInteren;
			modeTemSwitcher<= busMode;
		
		END IF;		
	END PROCESS;

end Behavioral;

